package model

import "gorm.io/gorm"

type Product struct {
	gorm.Model
	Name   string  `gorm:"type:varchar(50);not null"`
	Price  float64 `gorm:"type:decimal(10,2);not null"`
	Stock  int64   `gorm:"type:int(11);not null"`
	UserId int     `gorm:"type:int(11);not null"`
}

func (p *Product) FindProduct(db *gorm.DB, name string) error {
	return db.Debug().Where("name=?", name).Find(p).Error
}

func (p *Product) CreateProduct(db *gorm.DB) error {
	return db.Debug().Create(p).Error
}

func (p *Product) FindProductId(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Find(p).Error
}

func (p *Product) UpdateProduct(db *gorm.DB) error {
	return db.Debug().Updates(p).Error
}
